#!/usr/bin/env bash

. include/conf.sh
OUTPUTPATH=/tmp/$(rand)

cat zone/zone.head > ${OUTPUTPATH}/${NETSHORTNAME}-zone
mkdir ${OUTPUTPATH}
echo -n '' > ${OUTPUTPATH}/${NETSHORTNAME}-zone-normal
echo -n '' > ${OUTPUTPATH}/${NETSHORTNAME}-zone-rr

cat conf/network.conf | grep '^S:' |
while read line
do
        if [ `echo $line | cut -d ':' -f 5 | grep -c 'r'` != 0 ]
        then
                echo "`echo $line | cut -d ':' -f 2 | tr -d \"\n\"`    IN    A    `echo $line | cut -d ':' -f 3 | tr -d \"\n\"`" >> ${OUTPUTPATH}/${NETSHORTNAME}-zone-normal
                echo "irc    IN    A    `echo $line | cut -d ':' -f 3 | tr -d \"\n\"` ; `echo $line | cut -d ':' -f 2 | tr -d \"\n\"`" >> ${OUTPUTPATH}/${NETSHORTNAME}-zone-rr
        fi
done

cat ${OUTPUTPATH}/${NETSHORTNAME}-zone > geekshed.net.hosts
cat ${OUTPUTPATH}/${NETSHORTNAME}-zone-normal >> geekshed.net.hosts
echo >> geekshed.net.hosts
echo '; Round Robin' >> geekshed.net.hosts
cat ${OUTPUTPATH}/${NETSHORTNAME}-zone-rr >> geekshed.net.hosts

cat geekshed.net.hosts

echo
echo

#sudo /usr/sbin/rndc reload geekshed.net

rm -rf ${OUTPUTPATH}
